import { defineConfig } from 'vite'
import legacy from '@vitejs/plugin-legacy'
import vue from '@vitejs/plugin-vue'
const path = require('path')

// 通过项目名来指定生产环境的路径
import pagejson from './package.json'
const baseUrl = '//img.cdn.dn8188.com'
const prodUrl = `${baseUrl}/activity/${pagejson.name}/` // 生成环境地址

export default defineConfig({
  plugins: [
    vue(),
    legacy({
      targets: ['ie 11'], // 需要兼容的目标列表，可以设置多个
      additionalLegacyPolyfills: ['regenerator-runtime/runtime'], // 面向IE11时需要此插件
    }),
  ],
  resolve: {
    alias: [
      {
        find: '@',
        replacement: path.resolve(__dirname, 'src'),
      },
    ],
  },
  base: process.env.NODE_ENV === 'production' ? prodUrl : './',
  server: {
    host: '0.0.0.0',
    open: true,
  },
  build: {
    target: 'modules',
    assetsDir: 'images',
    brotliSize: false,
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@import "./src/assets/styles/_variables.scss";`, //你的scss文件路径
      },
      less: {
        modifyVars: {
          'primary-color': 'rgba(251, 191, 36, 1)',
        },
        javascriptEnabled: true,
      },
    },
  },
})
